<?php

namespace App\Models\CacheModel\chat;

use app\common\lib\exception\ApiException;
use App\Models\Api\BaseCache;
use think\Exception;

class HzDefaultReplyQuestion extends BaseCache
{
    protected $table = 'haozhungpt_ai.hz_default_reply_question';

    protected $cacheModel = 'chat.default_reply_question';

    protected $textCacheData = [];

    /**
     * 重写数据时获取数据
     * @param $ids
     * @param $type
     * @param $sortType
     * @return array
     * @throws ApiException
     */
    public function getInfoByIdsInData($ids, $type, $sortType)
    {
        try
        {
            $data = $this->where(['id' => ['in', $ids], 'status' => 1])->column('question,content', 'id');
        }
        catch (Exception $e)
        {
            $data = [];
        }

        return $data;
    }

    /**
     * 通过ID 获取词条
     * @param int $id
     * @return mixed
     * @throws \Exception
     */
    public function getTextById(int $id)
    {
        if (!isset($this->textCacheData[$id]))
        {   // 数据存在 直接获取
            $this->textCacheData[$id] = $this->getInfoById($id);
        }

        return $this->textCacheData[$id];
    }
}
